<?php
include "mysqli_connection.php";

$query = "SELECT Course_Group.c_id, Courses.prefix, Courses.number FROM Course_Group INNER JOIN Courses WHERE (g_id = ? ) AND (Courses.c_id = Course_Group.c_id);";
$stmt = $mysqli->stmt_init();
if ($stmt = $mysqli->prepare($query)){
	$stmt->bind_param("i", trim($_POST["g_id"]));
	$stmt->execute();
	$stmt->bind_result($c_id, $prefix, $number);
}
$text = "";
if (isset($stmt)){
	while ($stmt->fetch()){
		if ($text !== ""){
			$text .= ", ";
		}
		$text .= "<a href = 'managecourses.php?index=" . $c_id . "'>" . $prefix . " " . $number . "</a>";
	}
	$stmt->close();
}
if ($text !== ""){
	echo "<div>" . $text . "</div>";
}
else{
	echo "<div>No courses</div>";
}